package com.joy.joyusers.script;
import java.util.Date;

import cn.hutool.core.date.StopWatch;
import com.joy.joyusers.mapper.UserMapper;
import com.joy.joyusers.model.domain.User;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class InsertUser {

    @Resource
    private UserMapper userMapper;

    /**
     * 批量创建用户
     * 循环插入10000000条数据
     */
//    @Scheduled(initialDelay = 5000, fixedRate = Long.MAX_VALUE)
    public void doInsertUser() {
        // 测试
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        final int INSERT_NUM = 1000;
        for (int i = 0; i < INSERT_NUM; i++) {
            User user = new User();
            user.setUsername("测试用户数据");
            user.setAccount("fakeuser");
            user.setAvatar("https://img2.woyaogexing.com/2024/01/26/eed59415e34db73c!400x400.jpg");
            user.setProfile("");
            user.setGender(0);
            user.setPassword("12345678");
            user.setPhone("123");
            user.setEmail("123");
            user.setStatus(0);
            user.setRole(0);
            user.setTags("[]");
            userMapper.insert(user);
        }
        stopWatch.stop();
        System.out.println(stopWatch.getTotalTimeMillis());

    }

}
